Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: zero copy vec #1469

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Jan 9, 2025

Changes:

  • light-zero-copy
    • removed unsafe code, WrappedMutPointer, WrappedPointer
    • use the zerocopy crate
    • combine traits into ZeroCopyTraits
    • enabled optional padding with const PAD: bool in ZeroCopyVec, ZeroCopyMutSlice and ZeroCopyCyclicVec
    • optional padding allows to work with unaligned bytes by deriving zerocopy::Unaligned for L & T
  • cleanup
  • batched-merkle-tree
    • replaced ZeroCopyVecUsize with ZeroCopyVecU64 (usize is no longer supported)
    • BatchMetadata in MerkleTreeAccount & QueueAccount refactor WrappedMutPointer -> zerocopy::Ref<&mut [u8], T>
      • implemented conversion From<u64> for BatchState
      • derive zerocopy traits for Batch (KnownLayout, Immutable, IntoBytes, FromBytes)
      • Batch replaced BatchState with u64 (to satisfy zerocopy traits)
      • Batch replaced bloom_filter_is_wiped bool with u8 and added getters and setters which return bool (zerocopy traits don't support bool)
  • merkle-tree-metadata
    • derive zerocopy traits
    • use light_utils::pubkey::Pubkey instead of solana_program::pubkey:.Pubkey for zero copy compatibility
  • light_utils
    • implement Pubkey with derived zerocopy traits, solana_program::pubkey::Pubkey and anchor_lang::prelude::Pubkey conversions
  • account-compression program
    • trait GroupAccess return Pubkey instead of &Pubkey necessary so that we can convert light_utils::pubkey::Pubkey to anchor::prelude::Pubkey (conversion is necessary because we need to derive zerocopy traits)
    • moved association check into light-batched-merkle-trees for batch_append, insert-into-queues,
  • light-system-program
    • check_program_owner_state_merkle_tree added generic condition to distinguish between append and nullify as an additional safeguard in case that invalid accounts are passed
    • refactored invoke/processor.rs
      • reading an account or address succeeds if the address does not exist or the account does exist prior to the transaction
        (prior reading an account that is modified in the same tx would fail, same for reading an address which is created in the same tx)
      • fixed and simplified condition to enter proof verification conditional (prior read-only accounts proven by index required a zkp in the same instruction even if reading the account didn't require an inclusion zkp)
      • introduce check_vec_capacity to check vector capacity (it's basically free in terms of CU)

@ananas-block ananas-block force-pushed the jorrit/experiment-zerocopy-vec branch from a9cc184 to 2acc67c Compare January 9, 2025 20:50
cleanup
@ananas-block ananas-block force-pushed the jorrit/experiment-zerocopy-vec branch from 382cdef to a029ab0 Compare January 9, 2025 22:53
@ananas-block ananas-block force-pushed the jorrit/experiment-zerocopy-vec branch from 7c38f05 to 5e0c6de Compare January 9, 2025 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant